<template>
  <div>
    <baseTable :tableHeader="headerData" :tableData="tableData" @queryInfo="lookOver"></baseTable>
    <el-dialog title="提示" :visible.sync="dialogVisible" width="65%">

      <el-table :data="dialogData">
        <el-table-column type="index"></el-table-column>
        <el-table-column property="productId" label="产品编号" width="150"></el-table-column>
        <el-table-column property="productFile.productName" label="产品名称" width="150"></el-table-column>
        <el-table-column property="productFile.protDescribe" label="产品描述" width="150"></el-table-column>
        <el-table-column property="productNumber" label="生产数量" width="150"></el-table-column>
        <el-table-column property="sumPrice" label="小计" width="150"></el-table-column>
      </el-table>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="planPass">通 过</el-button>
        <el-button type="primary" @click="planNoPass">不通过</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
  import baseTable from '@/components/table/baseTable'
  import productionPlan from '@/api/apis/productionPlan'
  export default {
    data() {
      return {
        headerData: [{
            prop: 'productionId',
            label: '生产计划编号',
            minWidth: '100px',
            sortable: 'true'
          },
          {
            prop: 'productNumber',
            label: '生产总数',
            minWidth: '100px',
          },
          {
            prop: 'sumPrice',
            label: '小计',
            minWidth: '100px',
          },
          {
            prop: 'registerName',
            label: '登记人',
            minWidth: '100px',
          },
          {
            prop: 'createTime',
            label: '登记时间',
            minWidth: '100px',
          },
          {
            prop: 'oper',
            label: '操作',
            fixed: 'right',
            minWidth: '140px',
            oper: [{
              name: '审核',
              clickFun: 'queryInfo'
            }]
          }
        ],
        dialogVisible: false,
        tableData: [],
        dialogData: [],
        productionIdFlag: ''
      }
    },
    components: {
      baseTable
    },
    mounted() {
      this.productionPlanInit()
    },
    methods: {
      lookOver(row) {
        this.dialogVisible = true
        this.productionIdFlag = row.productionId
        productionPlan.findPlanProdcut(row.productionId)
          .then(resp => {
            if (resp.code === 200) {
              this.dialogData = resp.data
            } else {
              this.$message.error(resp.msg)
            }
          })
          .catch(err => {
            console.log(err)
          })
      },
      productionPlanInit() {
        productionPlan.findProductionPlan()
          .then(resp => {
            if (resp.code === 200) {
              this.tableData = resp.data
            } else {
              this.$message.error(resp.msg)
            }
          })
          .catch(err => {
            console.log(err)
          })
      },
      updatePlanStatus(status) {
        productionPlan.updateStatus(this.productionIdFlag,status)
        .then(resp => {
          if(resp.code === 200) {
            this.$message.success(resp.msg)
            this.productionPlanInit()
            this.dialogVisible = false
          } else {
            this.$message.error(resp.msg)
          }
        })
        .catch(err => {
          console.log(err)
        })
      },
      planPass() {
        if(!this.productionIdFlag) {
          return false
        } else {
          this.updatePlanStatus(2)
        }
      },
      planNoPass() {
        if(!this.productionIdFlag) {
          return false
        } else {
          this.updatePlanStatus(3)
        }
      }
    }
  }
</script>

<style>
</style>
